<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 2017/1/15
 * Time: 下午5:39
 */
class WarningService extends Service{

    public static function onlineHeader(){
        return array(
            'id'                    => array('text' => 'ID'),
            'create_time'           => array('text' => '报警时间'),
            'last_online_nume'      => array('text' => '上分钟在线'),
            'current_online_num'    => array('text' => '本分钟在线'),
            'dValue'                => array('text' => '在线差值'),
//            'status'                => array('text' => '状态'),
            'action'                => array('text' => '操作'),
        );
    }

    public static function onlineData($params){
        $model = new ModOnlineWarning();
        $args = array();
        if(!empty($params['status'])){
            $args['status'] = $params['status'];
        }

        $result = array();
        $tmp = $model->findAllByAttributes($args);
        $onlineStatus = self::onlineStatus();
        foreach($tmp as $v){
            $oneTmp = $v->attributes;
            $oneTmp['status'] = $onlineStatus[$oneTmp['status']];
            $oneTmp['create_time'] = date('Y-m-d H:i:s', $oneTmp['create_time']);
            $oneTmp['dValue'] = $oneTmp['current_online_num'] - $oneTmp['last_online_num'];

            $result[] = $oneTmp;
        }

        return $result;
    }

    public static function getOnlineInfo(){
        $model = new ModOnlineInfo();
        $result = $model->find(1)->attributes;
        return $result;
    }

    public static function saveSetting($params){
        $model = new ModOnlineInfo();
        $model->updateByPk('1', array(
            'mail_list'     => $params['mail'],
            'threshold'     => $params['threshold']
        ));
    }

    public static function onlineStatus(){
        return array(
            ''  => '全部',
            '1' => '新报警',
            '2' => '已解决',
            '3' => '已忽略',
        );
    }

}